/*
 * Buffer.cpp
 *
 *  Created on: 18/09/2012
 *      Author: rcasal
 */

#include "Buffer.h"

namespace ordenamiento {


int Buffer::getCapacidad(){
	return this->tam_max;
}

int Buffer::getCantidad(){
	return this->cant_datos;
}

void Buffer::swap(int pos1, int pos2){
	this->datos[pos1].swap(this->datos[pos2]);
}

string Buffer::getDato(int pos){
	return this->getDatos()[pos];
}

string * Buffer::getDatos(){
	return this->datos;
}

Buffer::Buffer(){
	this->tam_max = 0;
	this->cant_datos = 0;
	this->datos = NULL;
}

Buffer::Buffer(int tam_max) {
	this->tam_max = tam_max;
	this->cant_datos = 0;
	this->datos = new string[this->tam_max];
}

void Buffer::set(int tam_max){
	this->tam_max = tam_max;
	this->cant_datos = 0;
	this->datos = new string[this->tam_max];
}

void Buffer::addDato(int pos, string dato){
	this->datos[pos] = dato;
	//this->cant_datos++;
}

void Buffer::addDato(string dato){
	this->datos[this->cant_datos] = dato;
	this->cant_datos++;
}

void Buffer::vaciar(){
	for(int i = 0; i < this->cant_datos; i++){
		this->datos[i].clear();
	}
	this->cant_datos = 0;
}

string Buffer::toString(){
	string data = "---Buffer ToString---\n";
	for(int i; i < this->cant_datos; i++){
		data.append(this->datos[i] + "\n");
	}
	return data;
}

//Destructor
Buffer::~Buffer() {
}



/******************************************************/
/******************************************************/

QBuffer::QBuffer(){
	this->capacity = 0;
}

QBuffer::QBuffer(int capacity){
	this->capacity = capacity;
}

void QBuffer::setCapacity(int capacity){
	this->capacity = capacity;
}

void QBuffer::popRecord(){
	this->registros.pop();
}

RecordTermino QBuffer::getRecord(){
	return this->registros.front();
}

void QBuffer::pushRecord(RecordTermino r){
	if (this->capacity == (int)this->registros.size())
		throw exception();
	this->registros.push(r);
}

bool QBuffer::empty(){
	return this->registros.empty();
}

int QBuffer::size(){
	return (int)this->registros.size();
}

QBuffer::~QBuffer(){
}


} /* namespace ordenamiento */
